package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class WindowMess extends JFrame implements ActionListener{
	private static final long serialVersionUID = 4174621914605686809L;

	JTextField inputEnglish;
	JTextArea show;
	String regex = "[a-zA-Z]+";
	
	public WindowMess() {
		inputEnglish = new JTextField(22);
		inputEnglish.addActionListener(this);
		show = new JTextArea();
		add(inputEnglish, BorderLayout.NORTH);
		add(show, BorderLayout.CENTER);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == inputEnglish) {
			String string = inputEnglish.getText();
			if (string.matches(regex)) {
				show.append(string + ",0");
			} else {
				JOptionPane.showMessageDialog(this, "您输入了非法字符", "警告", JOptionPane.WARNING_MESSAGE); //对话框
				inputEnglish.setText(null);
			}
		}
	}
	
}
